/*
 =============================================================================
 FILE...............: AirportController.java
 COMMENTS...........: Controller class that works as a mediator between the
 					  GUI requests for airports and the persistence layer
 					  (accessed through the AirportDAO class).
 =============================================================================
 AUTHOR(S)..........: Everton Ranielly de Sousa Cavalcante
 					  Department of Informatics and Applied Mathematics
 					  Federal University of Rio Grande do Norte
 LAST MODIFICATION..: September 13th, 2012
 ============================================================================= 					  
*/


/* ========================================================================= */
/* PACKAGES			                                                         */
/* ------------------------------------------------------------------------- */
package test.control;


/* ========================================================================= */
/* IMPORTS			                                                         */
/* ------------------------------------------------------------------------- */
import java.util.Collections;
import java.util.List;
import java.util.Vector;

import dao.AirportDAO;

import model.Airport;


/* ========================================================================= */
/* CLASS AirportController                                                   */
/* ------------------------------------------------------------------------- */
/**
 * Controller class that works as a mediator between the GUI requests for 
 * airports and the persistence layer (accessed through the AirportDAO class)
 * @author Everton Cavalcante
 */
public class AirportController 
{
	/** Constructor */
	public AirportController()
	{ /* Empty */ }
	
	
	/**
	 * Retrieves all airport locations registered in the database
	 * @return List of airport locations
	 */
	public Vector<String> getAirports() 
	{
		// Creates an AirportDAO class instance
		AirportDAO airportDAO = new AirportDAO();
		
		// Retrieves all airports registered in the database
		List<Airport> airports = airportDAO.getAll();
		
		/* Iterates over the retrieved airports in order to get only
		 * airport locations */
		Vector<String> airportsLocation = new Vector<String>();
		for (Airport a : airports)
		{
			if (a.getAirportIATACode().equals(""))
				airportsLocation.add(a.getAirportICAOCode() + " - " + a.getAirportLocation());
			else
				airportsLocation.add(a.getAirportIATACode() + " - " + a.getAirportLocation());
		}
		
		// Sort airport locations
		Collections.sort(airportsLocation);
		
		return airportsLocation;
	}
}
